package com.liujit.upms.controller;

import com.liujit.common.domain.params.BaseParams;
import com.liujit.common.domain.result.DictItem;
import com.liujit.common.domain.result.PageBean;
import com.liujit.upms.domain.params.SysDictItemParams;
import com.liujit.upms.domain.query.SysDictItemQuery;
import com.liujit.upms.domain.result.SysDictItemResult;
import com.liujit.upms.service.SysDictItemService;
import com.liujit.validator.group.AddGroup;
import com.liujit.validator.group.ModifyGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 系统字典数据管理接口
 * @Author liujun
 * @Date 2021-07-02 14:52:34
 */
@RequiredArgsConstructor
@Api(tags = "系统字典数据管理接口")
@RestController
@RequestMapping("/sys/dict/item")
public class SysDictItemController {

    private final SysDictItemService sysDictItemService;

    @ApiOperation(value = "分页查询", notes = "根据系统字典数据分页查询条件，分页查询系统字典数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "系统字典数据分页查询条件", dataType = "SysDictItemQuery", dataTypeClass = SysDictItemQuery.class, paramType = "query") })
    @GetMapping("/getPage")
    public PageBean<SysDictItemResult> getPage(SysDictItemQuery query) {
        return sysDictItemService.getPage(query);
    }

    @ApiOperation(value = "添加", notes = "根据系统字典数据添加请求参数，添加系统字典数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统字典数据添加请求参数", dataType = "SysDictItemParams", dataTypeClass = SysDictItemParams.class, paramType = "body") })
    @PostMapping("add")
    public Boolean add(@RequestBody @Validated(AddGroup.class) SysDictItemParams params) {
        return sysDictItemService.save(params);
    }

    @ApiOperation(value = "修改", notes = "根据系统字典数据修改请求参数，修改系统字典数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统字典数据修改请求参数", dataType = "SysDictItemParams", dataTypeClass = SysDictItemParams.class, paramType = "body") })
    @PostMapping("/modify")
    public Boolean modify(@RequestBody @Validated(ModifyGroup.class) SysDictItemParams params) {
        return sysDictItemService.save(params);
    }

    @ApiOperation(value = "查询", notes = "根据系统字典数据id，查询系统字典数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统字典数据id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/get")
    public SysDictItemResult get(Long id) {
        return sysDictItemService.get(id);
    }

    @ApiOperation(value = "删除", notes = "根据系统字典数据删除请求参数，删除系统字典数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统字典数据删除请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/del")
    public Boolean del(@RequestBody BaseParams params) {
        return sysDictItemService.del(params);
    }

    @ApiOperation(value = "启用", notes = "根据系统字典数据启用请求参数，启用系统字典数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统字典数据启用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/enabled")
    public Boolean enabled(@RequestBody BaseParams params) {
        return sysDictItemService.enabled(params);
    }

    @ApiOperation(value = "禁用", notes = "根据系统字典数据禁用请求参数，禁用系统字典数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统字典数据禁用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/disabled")
    public Boolean disabled(@RequestBody BaseParams params) {
        return sysDictItemService.disabled(params);
    }

    @ApiOperation(value = "查询条数", notes = "根据系统字典数据，查询系统字典条数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统字典数据id", dataType = "Long", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "label", value = "系统字典数据", dataType = "String", dataTypeClass = String.class, paramType = "query") })
    @GetMapping("/getCountByLabel")
    public Integer getCountByLabel(Long id, String label) {
        return sysDictItemService.getCountByLabel(id, label);
    }

    @ApiOperation(value = "查询条数", notes = "根据系统字典数据，查询系统字典条数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统字典数据id", dataType = "Long", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "系统字典数据", dataType = "String", dataTypeClass = String.class, paramType = "query") })
    @GetMapping("/getCountByValue")
    public Integer getCountByValue(Long id, String value) {
        return sysDictItemService.getCountByValue(id, value);
    }

    @ApiOperation(value = "查询字典列表", notes = "根据系统字典数据编号，查询系统字典列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "系统字典数据编号", dataType = "String", dataTypeClass = String.class, paramType = "query") })
    @GetMapping("/getDictItem")
    public List<DictItem> getDictItem(String code) {
        return sysDictItemService.getDictItem(code);
    }
}
